const http = require("http");
let server = http.createServer((req, res) => {
  if (req.method === "POST") {
    // req.headers -> 获取客户端传递的所有请求头
    // req content-type application/json
    console.log("req content-type", req.headers["content-type"]);
    // 接收数据 ->  流方式接收数据
    let postData = "";
    req.on("data", (chunk) => {
      postData += chunk.toString();
    });
    req.on("end", () => {
      // postData： {
      //    "name":"张三",
      //    "age":25
      //  }

      console.log("postData：", postData);
      res.end("hello");
    });
  }
});
server.listen(8000, () => {
  console.log("服务启动成功 请访问 http://localhost:8000/");
});
